package com.yuyou.activity.comm.api.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.yuyou.activity.util.util.HttpClient;
import com.yuyou.activity.util.util.ZyPaySignUtil;

@RestController
@RequestMapping(value="/api/pay/test")
public class PayTestController {
	
	String appId="yyyxxt";
	String appKey="TSGJtLSLkkhkLSHJ46j";
	
	String create_order="https://paytest.zy.com/order";
	String query_order="https://paytest.zy.com/order/paystatus";
	String refund_order="https://paytest.zy.com/refund";
	
	
    @RequestMapping(value ="/createOrder",method = {RequestMethod.GET, RequestMethod.POST})
    public String createOrder(String orderId) throws Exception{
    	
        Map<String, String> params = new HashMap<>();
        params.put("id", String.valueOf(new Date().getTime()));
        params.put("version", "1.0");
        params.put("appId", appId);
        params.put("orderId", orderId);
        params.put("amount", "1");
        params.put("orderName", orderId);
        params.put("orderContent", orderId);
        params.put("orderCreateTime", String.valueOf(new Date().getTime()) );
        params.put("userId", orderId);
        params.put("returnUrl", "http://test.h5.game.yuyou100.com/activity-gateway/comm-api/api/pay/order/return?a=1");
        params.put("merCode", "yygz");
        params.put("attach", "{sys_code:1,project_code:2}");
        String sign=ZyPaySignUtil.sign(params, appKey);
        params.put("sign", sign);		
        String s=HttpClient.postUtf8(create_order, params, null);
        System.out.println(s);		
    	
        return s; 
    }
	
    
    @RequestMapping(value ="/queryOrder",method = {RequestMethod.GET, RequestMethod.POST})
    public String queryOrder(String payOrderId) throws Exception{  
    	
        Map<String, String> params = new HashMap<>();
        params.put("payOrderId", payOrderId);	
        String s=HttpClient.get(query_order, params);
        System.out.println(s);	
        return s; 
    }

    

    @RequestMapping(value ="/refundOrder",method = {RequestMethod.GET, RequestMethod.POST})
    public String refundOrder(String refundId,String orderId) throws Exception{  
        Map<String, String> params = new HashMap<>();
        params.put("id", String.valueOf(new Date().getTime()));
        params.put("version", "1.0");
        params.put("appId", appId);
        params.put("refundId", refundId);
//        params.put("trxId", "10");
        params.put("orderId", orderId);
        params.put("refundAmount", "1");
        params.put("bizApprover", "test");
        params.put("bizApproveTime", String.valueOf(new Date().getTime()) );
        //params.put("attach", null);
        String sign=ZyPaySignUtil.sign(params, appKey);
        params.put("sign", sign);		
        String s=HttpClient.postUtf8(refund_order, params, null);
        System.out.println(s);	    	
        return s; 
    }
    
    
    
    
    
	
}
